/***********************************************************************/
/*                                                                     */
/*  FILE        :intprg.c                                              */
/*  DATE        :Tue, Jun 03, 2014                                     */
/*  DESCRIPTION :define the top address of the interrupt vectors.      */
/*  CPU GROUP   :2D                                                    */
/*                                                                     */
/*  This file is generated by Renesas Project Generator (Ver.4.19).    */
/*  NOTE:THIS IS A TYPICAL EXAMPLE.                                    */
/***********************************************************************/
/*********************************************************************
 *
 * Device     : R8C/2C,2D
 *
 * File Name  : intprg.c
 *
 * Abstract   : Define variable vector table.
 *
 * History    : 1.10  (2007-05-29)
 *            : 1.11  (2010-10-01)
 *
 * NOTE       : THIS IS A TYPICAL EXAMPLE.
 *
 * Copyright (C) 2007 (2010) Renesas Electronics Corporation.
 * Renesas Solutions Corp.
 *
 *********************************************************************/
#include "sfr_r82d.h"
#include "cstartdef.h"
#include "../../../dev/timer.h"
#include "../../../dev/uart.h"
#include "../../../app/shell.h"
#include "../../../dev/key.h"
#include "../../../hal/modbus/ms_protocol/common.h"
#include "../../../dev/485.h"
#include "../../../hal/hal_seven_seg_led.h"
#include "../../../lib/delay.h"
#include "../../../dev/interrupt.h"

extern uint32 time_1ms_tick;
extern uint8 key_timeout;
extern uint8 led_location;
//extern uint8 cmd[100];

extern receive_frame_struct slave_receive_frame;


// When you want to use BANK1 registers
// please define interrupt using /B swtich as follows.
//
//  #pragma interrupt/B xxxx
//

// BRK				(software int 0)
#pragma interrupt	_brk(vect=0)
void _brk(void);
void _brk(void) {
}

// vector 1 reserved
// vector 2 reserved
// vector 3 reserved
// vector 4 reserved
// vector 5 reserved
// vector 6 reserved

// timer RC 			(software int 7)
#pragma interrupt	_timer_rc(vect=7)
void _timer_rc(void);
void _timer_rc(void) {
}

// timer RD (channel 0)		(software int 8)
#pragma interrupt	_timer_rd0(vect=8)
void _timer_rd0(void);
/*! \brief while the pluse was occurred,it will be entered  and if there is a variable in this function , it looks like a counter for pluse
* \param
* \retrun
*/
void _timer_rd0(void) {
    if (imfc_trdsr0) {
        imfc_trdsr0 = 0;
    }
}

// timer RD (channel 1)		(software int 9)
#pragma interrupt	_timer_rd1(vect=9)
void _timer_rd1(void);
void _timer_rd1(void) {
}

// timer RE			(software int 10)
#pragma interrupt	_timer_re(vect=10)
void _timer_re(void);
void _timer_re(void) {
}

// UART2 transmit		(software int 11)
extern uint8 uart2_buffer_count;
extern uart_tx_buffer tx2_buffer;
#pragma interrupt	_uart2_transmit(vect=11)
void _uart2_transmit(void);
void _uart2_transmit(void) {
    if (tx2_buffer.tx_data_len != uart2_buffer_count) {
        nodelay_send_byte(tx2_buffer.tx_data[uart2_buffer_count]);
        uart2_buffer_count++;
    } else {
        uart2_buffer_count = 0;
        tx2_buffer.tx_data_len = 0;
        tx2_buffer.tx_done = 1;
#ifdef MODBUS_ENABLE
        set_485(RX_485);
#endif
    }
}

// UART2 receive		(software int 12)
#pragma interrupt	_uart2_receive(vect=12)
void _uart2_receive(void);
void _uart2_receive(void) {
    uint8 receive_status = u2rbh;
    uint8 receive_data;
    if ((receive_status & 0xF0) == 0) {
        receive_data = u2rbl;
#ifdef __DEBUG__
        debug_nodelay_send_byte(receive_data);
#endif
#ifdef MODBUS_ENABLE
        modbus_operation.receive_frame_function(receive_data);
#endif
    }
}

// input_key			(software int 13)
#pragma interrupt	_input_key(vect=13)
void _input_key(void);
void _input_key(void) {
}

// vector 14 reserved

// SSUIC/IICIC			(software int 15)
#pragma interrupt	_ssuic(vect=15)
void _ssuic(void);
void _ssuic(void) {
}

// compare1			(software int 16)
#pragma interrupt	_compare1(vect=16)
void _compare1(void);
void _compare1(void) {
}

#if (__STANDARD_IO__ != 0) && defined(__UART0__)
// UART0 can't be used
#else
extern uint8 uart0_buffer_count;
extern uart_tx_buffer tx0_buffer;
// UART0 transmit		(software int 17)
#pragma interrupt	_uart0_transmit(vect=17)
void _uart0_transmit(void);
void _uart0_transmit(void) {
//    if (tx0_buffer.tx_data_len != uart0_buffer_count) {
//        nodelay_send_byte(tx0_buffer.tx_data[uart0_buffer_count]);
//        uart0_buffer_count++;
//    } else {
//        uart0_buffer_count = 0;
//        tx0_buffer.tx_data_len = 0;
//        tx0_buffer.tx_done = 1;
//#ifdef MODBUS_ENABLE
//        set_485(RX_485);
//#endif
//    }
}

// UART0 receive		(software int 18)
#pragma interrupt	_uart0_receive(vect=18)
void _uart0_receive(void);
void _uart0_receive(void) {
//    uint8 receive_status = u0rbh;
//    uint8 receive_data;
//    if ((receive_status & 0xF0) == 0) {
//        receive_data = u0rbl;
//#ifdef __DEBUG__
//        debug_nodelay_send_byte(receive_data);
//#endif
//#ifdef MODBUS_ENABLE
//        modbus_operation.receive_frame_function(receive_data);
//#endif
//    }
}
#endif

#if defined(__FOUSB__) || defined(__E8__) || ((__STANDARD_IO__ != 0) && !defined(__UART0__))
// UART1 can't be used
#else
// UART1 transmit		(software int 19)
#pragma interrupt	_uart1_transmit(vect=19)
void _uart1_transmit(void);
void _uart1_transmit(void) {
}

// UART1 receive		(software int 20)
#pragma interrupt	_uart1_receive(vect=20)
void _uart1_receive(void);
void _uart1_receive(void) {
    uint8 receive_status = u1rbh;
    uint8 receive_data;
    if ((receive_status & 0xF0) == 0) {
        receive_data = u1rbl;
    }
}
#endif

// int2				(software int 21)
#pragma interrupt	_int2(vect=21)
void _int2(void);
void _int2(void) {
}

// timer RA			(software int 22)
#pragma interrupt	_timer_ra(vect=22)
void _timer_ra(void);
void _timer_ra(void) {
    time_1ms_tick++;
#ifdef MODBUS_ENABLE
    mb_check_timeout();
#endif
}

// vector 23 reserved
// timer RB			(software int 24)
#pragma interrupt	_timer_rb(vect=24)
void _timer_rb(void);
void _timer_rb(void) {
#ifdef MENU_ENABLE
#ifdef __SIMPLE_DISPLAY__
    hal_seven_seg_display();
#endif
#endif
}

// int1				(software int 25)
#pragma interrupt	_int1(vect=25)
void _int1(void);
void _int1(void) {
    debug_send_byte(255);
    ir_int1ic = 0;
}

// int3				(software int 26)
#pragma interrupt	_int3(vect=26)
void _int3(void);
void _int3(void) {
}

// timer RF			(software int 27)
#pragma interrupt	_timer_rf(vect=27)
void _timer_rf(void);
void _timer_rf(void) {
}

// compare0 			(software int 28)
#pragma interrupt	_compare0(vect=28)
void _compare0(void);
void _compare0(void) {
}

// int0				(software int 29)
#pragma interrupt	_int0(vect=29)
void _int0(void);
void _int0(void) {
    debug_send_byte(0);
    ir_int0ic = 0;
}

// AD converter			(software int 30)
#pragma interrupt	_ad_converter(vect=30)
void _ad_converter(void);
void _ad_converter(void) {
}

// capture			(software int 31)
#pragma interrupt	_capture(vect=31)
void _capture(void);
void _capture(void) {
}

// vector 32 for user
// vector 33 for user
// vector 34 for user
// vector 35 for user
// vector 36 for user
// vector 37 for user
// vector 38 for user
// vector 39 for user
// vector 40 for user
// vector 41 for user
// vector 42 for user
// vector 43 for user
// vector 44 for user
// vector 45 for user
// vector 46  for user
// vector 47  for user
// vector 48  for user
// vector 49  for user
// vector 50  for user
// vector 51  for user
// vector 52  for user
// vector 53  for user
// vector 54  for user
// vector 55  for user
// vector 56  for user
// vector 57  for user
// vector 58  for user
// vector 59  for user
// vector 60  for user
// vector 61  for user
// vector 62  for user
// vector 63  for user

